#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;


class Solution {
public:
    vector<vector<int>> threeSum(vector<int>& nums)
    {
        vector<vector<int>> v;
        sort(nums.begin(), nums.end());
        for (int i = 0; i <= nums.size() - 3; i++)
        {
            int left = i + 1, right = nums.size() - 1;
            if (i > 0 && i <= nums.size() - 3 && nums[i] == nums[i - 1])
            {
                continue;
            }
            else
            {
                while (left < right)
                {
                    if (left != i + 1 && left < right && nums[left] == nums[left - 1])
                    {
                        left++;
                        continue;
                    }
                    int sum = nums[left] + nums[right];
                    if (-sum == nums[i])
                        v.push_back({ nums[left],nums[right],nums[i] }), left++, right--;
                    else if (-sum < nums[i])
                        right--;
                    else
                        left++;

                }
            }

        }

        return v;

    }
};


int main()
{
    vector<int> v({ -1,0,1,2,-1,-4 });
    vector<vector<int>> vt=Solution().threeSum(v);



    return 0;
}